package com.example.core.utils;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.enums.TimeEnums;

import java.util.Date;

public class QueryWrapperUtils {

    /****
     *
     * 时间区间绑定
     * @param timeEnums
     * @param queryWrapper
     */
    public static void buildTimeQuery(TimeEnums timeEnums, QueryWrapper queryWrapper) {
        //本周
        if (timeEnums.getValue().equalsIgnoreCase(TimeEnums.WEEK.getValue())) {
            queryWrapper.between("create_time", DateUtil.beginOfWeek(new Date()), new Date());
        }
        //本月
        if (timeEnums.getValue().equalsIgnoreCase(TimeEnums.MONTH.getValue())) {
            queryWrapper.between("create_time", DateUtil.beginOfMonth(new Date()), new Date());
        }
        //本年
        if (timeEnums.getValue().equalsIgnoreCase(TimeEnums.YEAR.getValue())) {
            queryWrapper.between("create_time", DateUtil.beginOfYear(new Date()), new Date());
        }
        //所有
        if (timeEnums.getValue().equalsIgnoreCase(TimeEnums.ALL.getValue())) {

        }
    }
}
